home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 4
/
Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso
/
Development
/
General
/
CW TCL port package
/
Template Munger
/
Source
/
main.c
next >
Wrap
Text File
|
1994-05-29
|
4KB
|
194 lines
/*
* main.c
*/
void Idle ( void ) ;
void Message ( unsigned char * ) ;
void Try ( short code ) ;
unsigned char * folder_to_munge = "\pTO MUNGE" ;
unsigned char * message_file = "\pMESSAGES" ;
unsigned char * output_folder = "\pTEMPLATE MACROS" ;
extern short out_vRef; // folder for output files
extern long out_parID;
Handle windowText = NULL ;
WindowPtr window = NULL ;
short vRefNum = 0 ;
Boolean done = 0 ;
extern void MungeFolder ( long parID ) ;
void
Try ( short code ) {
if ( code ) {
DebugStr ( "\pFailure!" ) ;
}
}
static void
InitMac ( ) {
InitGraf ( & qd . thePort ) ;
InitFonts ( ) ;
InitWindows ( ) ;
InitMenus ( ) ;
TEInit ( ) ;
InitDialogs ( NULL ) ;
}
static void
UpdateWindow ( ) {
Rect r = window -> portRect ;
InsetRect ( & r , 3 , 3 ) ;
TextFont ( GetAppFont ( ) ) ;
TextSize ( GetDefFontSize ( ) ) ;
HLock ( windowText ) ;
TextBox ( * windowText , GetHandleSize ( windowText ) , & r , teJustLeft ) ;
HUnlock ( windowText ) ;
}
static void
Click ( EventRecord * er ) {
WindowPtr win ;
short code ;
Rect limit = ( * GetGrayRgn ( ) ) -> rgnBBox ;
InsetRect ( & limit , 3 , 3 ) ;
code = FindWindow ( er -> where , & win ) ;
switch ( code ) {
case inSysWindow :
SystemClick ( er , win ) ;
break ;
case inDrag :
DragWindow ( win , er -> where , & limit ) ;
break ;
}
}
void
Idle ( ) {
EventRecord er ;
WaitNextEvent ( -1 , & er , 0L , NULL ) ;
switch ( er . what ) {
case mouseDown :
Click ( & er ) ;
break ;
case updateEvt :
SetPort ( window ) ;
BeginUpdate ( window ) ;
EraseRect ( & ( window -> portRect ) ) ;
UpdateWindow ( ) ;
EndUpdate ( window ) ;
break ;
}
}
static void
SetWindowText ( unsigned char * string ) {
PtrToXHand ( string + 1 , windowText , * string ) ;
SetPort ( window ) ;
UpdateWindow ( ) ;
}
void
Message ( unsigned char * message ) {
static short refNum = 0 ;
long len ;
static unsigned long last = 0 ;
do {
Idle ( ) ;
} while ( TickCount ( ) < last + 5 ) ;
last = TickCount ( ) ;
if ( ! message ) {
if ( refNum ) {
FSClose ( refNum ) ;
FlushVol ( NULL , 0 ) ;
}
refNum = 0 ;
return ;
}
if ( ! refNum ) {
Create ( message_file , 0 , 'MPS ' , 'TEXT' ) ;
Try ( FSOpen ( message_file , 0 , & refNum ) ) ;
Try ( SetEOF ( refNum , 0L ) ) ;
}
if ( refNum ) {
len = * message ;
Try ( FSWrite ( refNum , & len , message + 1 ) ) ;
}
SetWindowText ( message ) ;
}
static void
MakeWindow ( ) {
window = GetNewWindow ( 128 , NULL , NULL ) ;
if ( ! window ) {
Try ( -192 ) ;
}
windowText = NewHandle ( 0L ) ;
Message ( "\pWelcome!\r" ) ;
SelectWindow ( window ) ;
ShowWindow ( window ) ;
}
void
main ( ) {
CInfoPBRec rec ;
InitMac ( ) ;
MakeWindow ( ) ;
rec . hFileInfo . ioNamePtr = output_folder ;
rec . hFileInfo . ioVRefNum = 0 ;
rec . hFileInfo . ioDirID = 0 ;
rec . hFileInfo . ioFDirIndex = 0 ;
rec . hFileInfo . ioFlAttrib = 0;
PBGetCatInfoSync(&rec);
if ( rec . hFileInfo . ioFlAttrib & 0x10 ) {
out_vRef = rec.hFileInfo.ioVRefNum;
out_parID = rec.hFileInfo.ioDirID;
} else {
Message ( "\pTEMPLATE MACROS is not a folder!" ) ;
}
if (out_parID != 0) {
rec . hFileInfo . ioNamePtr = folder_to_munge ;
rec . hFileInfo . ioVRefNum = 0 ;
rec . hFileInfo . ioDirID = 0 ;
rec . hFileInfo . ioFDirIndex = 0 ;
rec . hFileInfo . ioFlAttrib = 0;
PBGetCatInfoSync(&rec);
if ( rec . hFileInfo . ioFlAttrib & 0x10 ) {
MungeFolder ( rec . hFileInfo . ioDirID ) ;
} else {
Message ( "\pTO MUNGE is not a folder!" ) ;
}
}
Message ( "\pClick To Exit\r" ) ;
Message ( NULL ) ;
Idle ( ) ;
}